﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;

public partial class account_referdone : FBasePage
{
    // Fields

    public string strUserID = "";
    public string strWebSite = "";

    // Methods
    private void initList(string strUserID)
    {
        int num;
        StringBuilder builder = new StringBuilder();
        builder.Append("<tr>");
        builder.Append("<th width=\"120\">被邀用户</th>");
        builder.Append("<th width=\"305\">项目名称</th>");
        builder.Append("<th width=\"150\">购买时间</th>");
        builder.Append("<th width=\"40\">返利</th>");
        builder.Append("</tr>");
        Maticsoft.BLL.Invite invite = new Maticsoft.BLL.Invite();
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.BLL.Team team = new Maticsoft.BLL.Team();
        string where = "   Credit !=0 and User_id=" + strUserID;
        DataSet set = DbHelperSQL.Page(10, this.pager.CurrentPageIndex, "Invite", where, " Create_time desc", "*", out num);
        if (((set != null) && (set.Tables.Count > 0)) && (set.Tables[0].Rows.Count > 0))
        {
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                DataRow row = set.Tables[0].Rows[i];
                if ((i % 2) != 0)
                {
                    builder.Append("<tr  id='team-list-id-" + row["id"] + "'>");
                }
                else
                {
                    builder.Append("<tr class=\"alt\"  id='team-list-id-" + row["id"] + "'>");
                }
                Maticsoft.Model.UserInfo model = info.GetModel(int.Parse(row["Other_user_id"].ToString()));
                if (model != null)
                {
                    builder.Append("<td class=\"style1\">" + model.Username + "</td>");
                }
                else
                {
                    builder.Append("<td class=\"style1\"></td>");
                }
                Maticsoft.Model.Team team2 = team.GetModel(int.Parse(row["Team_id"].ToString()));
                if (team2 != null)
                {
                    builder.Append("<td>" + team2.Title + "</td>");
                }
                else
                {
                    builder.Append("<td></td>");
                }
                builder.Append("<td>" + row["Buy_time"].ToString() + "</td>");
                builder.Append("<td>" + row["Credit"].ToString() + "</td>");
                builder.Append("</tr>");
            }
        }
        this.pager.RecordCount = num;
        this.ltRefer.Text = builder.ToString();
    }

    private void initText()
    {
        if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
        {
            base.Response.Redirect("Login.aspx");
        }
        DataSet list = new DataSet();
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        string name = this.Page.User.Identity.Name;
        string absolutePath = base.Request.Url.AbsolutePath;
        list = info.GetList(" Username='" + name + "'");
        if (((list != null) && (list.Tables.Count > 0)) && (list.Tables[0].Rows.Count > 0))
        {
            this.strUserID = list.Tables[0].Rows[0]["ID"].ToString();
        }
        this.initList(this.strUserID);
        this.strWebSite = base.Request.Url.AbsoluteUri;
        this.strWebSite = this.strWebSite.Substring(7);
        this.strWebSite = "http://" + this.strWebSite.Substring(0, this.strWebSite.IndexOf('/'));
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.MyWebside1.Select = "refer";
        if (!this.Page.IsPostBack)
        {
            this.initText();
        }
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        this.initText();
    }

}